/*
 *      EntryType.java
 *
 *      Copyright 2008 Pablo Nicolas Diaz Bilotto <pablonicolas.diaz@gmail.com>
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */
package lexer;


/**
 * The Enum EntryType.
 */
public enum EntryType {

	/** The NOTYPE. */
	NOTYPE {
		@Override
		public String toString() {

			return "";
		}

		@Override
		public String toGui() {
			// TODO Auto-generated method stub
			return "NOTYPE";
		}
	},

	/** The STRING. */
	STRING {
		@Override
		public String toString() {

			return "DB";
		}

		@Override
		public String toGui() {
			// TODO Auto-generated method stub
			return "STRING";
		}
	},

	/** The INT. */
	INT {
		@Override
		public String toString() {
			return "DW";
		}

		@Override
		public String toGui() {
			// TODO Auto-generated method stub
			return "INT";
		}
	},

	/** The DOUBLE. */
	DOUBLE {
		@Override
		public String toString() {
			return "DQ";
		}

		@Override
		public String toGui() {
			// TODO Auto-generated method stub
			return "DOUBLE";
		}
	};

	/**
	 * F.
	 *
	 * @param Type1 the type1
	 * @param Type2 the type2
	 *
	 * @return the entry type
	 */
	public static EntryType F(EntryType Type1, EntryType Type2) {
		if (Type1 == Type2 && isArimethicType(Type1) && isArimethicType(Type2))
			return Type1;
		else
			return NOTYPE;

	}

	/**
	 * Checks if is arimethic type.
	 *
	 * @param Type1 the type1
	 *
	 * @return true, if is arimethic type
	 */
	public static boolean isArimethicType(EntryType Type1) {
		return Type1 == INT || Type1 == DOUBLE;
	}

	/**
	 * Checks if is valued type.
	 *
	 * @param Type1 the type1
	 *
	 * @return true, if is valued type
	 */
	public static boolean isValuedType(EntryType Type1) {
		return isArimethicType(Type1) || Type1 == STRING;
	}

	/**
	 * Valid casting.
	 *
	 * @param Type1 the type1
	 * @param Type2 the type2
	 *
	 * @return true, if successful
	 */
	public static boolean ValidCasting(EntryType Type1, EntryType Type2) {
		if (!isArimethicType(Type1) || !isArimethicType(Type2)) {
			return false;
		}
		return (Type1 != Type2);
	}

	public static EntryType Casting(EntryType Type1,EntryType Type2) {
		if (!isArimethicType(Type1) || !isArimethicType(Type2))
			return NOTYPE;
		if (Type1 == INT && Type2==DOUBLE)
			return DOUBLE;
		else if (Type2 == INT && Type1==DOUBLE)
			return INT;
		else return NOTYPE;
	}

	public abstract String toGui() ;
}
